package board;

import character.Character;
import item.Item;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import game.DataStore;
import misc.Vector3i;

public class Tile extends Node {
    public static final float SIZE = 1.5f;
    public static final float SIZE_DIAGONAL = 2*FastMath.sqrt(0.5f*FastMath.sqr(SIZE));
    protected Geometry geometry;
    protected Vector3i boardLocation;
    protected Character character;
    protected Item item;

    public Tile() {
	geometry = new Geometry("tile", new Box(Tile.SIZE/2, Tile.SIZE/4, Tile.SIZE/2));
	Material mat = new Material(DataStore.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.LightGray);
        geometry.setMaterial(mat);
	this.attachChild(geometry);
    }
    
    public void highlight() {
        geometry.getMaterial().setColor("Color", ColorRGBA.Blue);
    }
    public void unhighlight() {
        geometry.getMaterial().setColor("Color", ColorRGBA.LightGray);
    }
    
    public Character getCharacter() {
        return character;
    }
    public void setCharacter(Character character) {
        this.character = character;
    }
    public void removeCharacter() {
        character = null;
    }
    public Item getItem() {
        return item;
    }
    public void setItem(Item item) {
        this.item = item;
    }
    public void removeItem() {
        item = null;
    }
    public Vector3i getBoardLocation() {
	return boardLocation;
    }
    public void setBoardLocation(Vector3i boardLocation) {
	this.boardLocation = boardLocation;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Tile other = (Tile) obj;
        if (this.boardLocation != other.boardLocation && (this.boardLocation == null || !this.boardLocation.equals(other.boardLocation))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + (this.boardLocation != null ? this.boardLocation.hashCode() : 0);
        return hash;
    }
}
